local guixin = fk.CreateSkill {
  name = "lingling__guixin",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__guixin"] = "归心",
  [":lingling__guixin"] = "锁定技，每轮限两次，当你受到伤害后，其他角色各交给你一张牌，交给你<font color='red'>♥</font>牌的角色摸一张牌。",

  ["#lingling__guixin-give"] = "归心：请交给 %src 一张牌，若交出<font color='red'>♥</font>牌则摸一张牌",
}

guixin:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(guixin.name) and
        player:usedSkillTimes(guixin.name, Player.HistoryRound) < 2 and
        table.find(player.room:getOtherPlayers(player, false), function(p)
          return not p:isNude()
        end)
  end,
  on_cost = function(self, event, target, player, data)
    event:setCostData(self, { tos = player.room:getOtherPlayers(player) })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if player.dead then return end
      if not p.dead and not p:isNude() then
        local card = room:askToCards(p, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = guixin.name,
          prompt = "#lingling__guixin-give:" .. player.id,
          cancelable = false,
        })
        local yes = Fk:getCardById(card[1]).suit == Card.Heart
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, guixin.name, nil, false, p)
        if yes and not p.dead then
          p:drawCards(1, guixin.name)
        end
      end
    end
  end,
})

return guixin
